package cn.bug.greenflag.controller;

import cn.bug.greenflag.pojo.dto.AdminAddNewDTO;
import cn.bug.greenflag.pojo.vo.AdminListItemVO;
import cn.bug.greenflag.service.IAdminService;
import cn.bug.greenflag.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 我
 */
@Slf4j
@RestController
@RequestMapping("/admins")
@Api(tags = "01. 管理员管理模块")
public class AdminController {
    @Autowired
    IAdminService adminService;
    @ApiOperation("添加管理员")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNewAdmin(AdminAddNewDTO adminAddNewDTO){
        log.debug("开始处理【添加管理员】的请求，参数：{}", adminAddNewDTO);
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询管理员列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<AdminListItemVO>> list() {
        log.debug("开始处理【查询管理员列表】的请求……");
        List<AdminListItemVO> list = adminService.list();
        return JsonResult.ok(list);
    }

}

